package com.xnyzc.lhy.order.controller.capi.order;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.service.order.IOaCOrderDetailsService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 获取订单详情
 * @Author zhuyubin
 * @Date 2019/8/15 19:55
 **/
@RestController
@RequestMapping(value = "capi/orderDetails")
public class OaCOrderDetailsController {

    @Autowired
    private IOaCOrderDetailsService iOaCOrderDetailsService;

    /**
     * 获取订单详情
     * @param orderNo 订单号
     * @return
     */
    @GetMapping(value = "getOrderDetails")
    public Rv getOrderDetails(@ApiParam(name = "orderNo", value = "订单号") @RequestParam(value = "orderNo") String orderNo){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        String userType = TokenUtil.getUserType();
        if (CheckUtil.objIsEmpty(userType, tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return Rv.wrap(iOaCOrderDetailsService.getOrderDetails(userId, tag, userType, orderNo));
    }

    @GetMapping(value = "getCostDetails")
    public Rv getCostDetails(@ApiParam(name = "orderNo", value = "订单号") @RequestParam(value = "orderNo") String orderNo){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return Rv.wrap(iOaCOrderDetailsService.getCostDetails(userId, tag, orderNo));
    }
}
